//
//  TopView.m
//  TraceViewer
//
//  Created by Vladimir Sarpe on 24/06/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "TopView.h"


@implementation TopView

- (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
		position = @"n/a";
	}
    return self;
}

-(void) notifyChangePositionLeft:(int)left andRight:(int)right {
	position = [NSString stringWithFormat:@"%d - %d", left, right];
	[self setNeedsDisplay:YES];
}

- (void)drawRect:(NSRect)rect {
	[[NSColor whiteColor] set];
	NSRectFill(rect);

	
	NSMutableAttributedString *s = [[NSMutableAttributedString alloc] initWithString:position];
	[s addAttribute:NSFontAttributeName	
			  value:[NSFont userFontOfSize:10]
			  range:NSMakeRange(0,[s length])];
	[s addAttribute:NSForegroundColorAttributeName
			  value:[NSColor blackColor]
			  range:NSMakeRange(0,[s length])];
	NSRect text = NSMakeRect(50, 50, 1000, 100);
	[s drawInRect:text];
	
	/*NSBezierPath *bp = [[NSBezierPath alloc] init];
	NSRect frameRect = [self bounds];
	[bp moveToPoint:NSMakePoint(0, 0)];
	[bp lineToPoint:NSMakePoint(frameRect.size.width, 0)];
	[bp moveToPoint:NSMakePoint(0, frameRect.size.height-60)];
	[bp lineToPoint:NSMakePoint(frameRect.size.width, frameRect.size.height-60)];
	[[NSColor blackColor] set];
	[bp stroke];
	
	float alpha = 0.25;
	
	NSBezierPath *bp2 = [[NSBezierPath alloc] init];
	[bp2 setLineWidth:3];
	[bp2 moveToPoint:NSMakePoint(0, frameRect.size.height-5)];
	[bp2 lineToPoint:NSMakePoint(frameRect.size.width, frameRect.size.height-5)];
	[bp2 stroke];
	
	NSBezierPath *bp3 = [[NSBezierPath alloc] init];
	[bp3 moveToPoint:NSMakePoint(80, frameRect.size.height-30)];
	[bp3 lineToPoint:NSMakePoint(180, frameRect.size.height-30)];
	[bp3 lineToPoint:NSMakePoint(180, frameRect.size.height-50)];
	[bp3 lineToPoint:NSMakePoint(80, frameRect.size.height-50)];
	[bp3 closePath];
	[[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:alpha] set];
	[bp3 fill];
	
	NSBezierPath *bp5 = [[NSBezierPath alloc] init];
	[bp5 moveToPoint:NSMakePoint(81, frameRect.size.height-31)];
	[bp5 lineToPoint:NSMakePoint(181, frameRect.size.height-31)];
	[bp5 lineToPoint:NSMakePoint(181, frameRect.size.height-51)];
	[bp5 lineToPoint:NSMakePoint(81, frameRect.size.height-51)];
	[bp5 closePath];
	[[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:alpha] set];
	[bp5 fill];
	
	NSBezierPath *bp6 = [[NSBezierPath alloc] init];
	[bp6 moveToPoint:NSMakePoint(82, frameRect.size.height-32)];
	[bp6 lineToPoint:NSMakePoint(182, frameRect.size.height-32)];
	[bp6 lineToPoint:NSMakePoint(182, frameRect.size.height-52)];
	[bp6 lineToPoint:NSMakePoint(82, frameRect.size.height-52)];
	[bp6 closePath];
	[[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:alpha] set];
	[bp6 fill];
	
	NSBezierPath *bp7 = [[NSBezierPath alloc] init];
	[bp7 moveToPoint:NSMakePoint(83, frameRect.size.height-33)];
	[bp7 lineToPoint:NSMakePoint(183, frameRect.size.height-33)];
	[bp7 lineToPoint:NSMakePoint(183, frameRect.size.height-53)];
	[bp7 lineToPoint:NSMakePoint(83, frameRect.size.height-53)];
	[bp7 closePath];
	[[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:alpha] set];
	[bp7 fill];
	
	NSBezierPath *bp8 = [[NSBezierPath alloc] init];
	[bp8 moveToPoint:NSMakePoint(84, frameRect.size.height-34)];
	[bp8 lineToPoint:NSMakePoint(184, frameRect.size.height-34)];
	[bp8 lineToPoint:NSMakePoint(184, frameRect.size.height-54)];
	[bp8 lineToPoint:NSMakePoint(84, frameRect.size.height-54)];
	[bp8 closePath];
	[[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:alpha] set];
	[bp8 fill];
	
	NSBezierPath *bp9 = [[NSBezierPath alloc] init];
	[bp9 moveToPoint:NSMakePoint(85, frameRect.size.height-35)];
	[bp9 lineToPoint:NSMakePoint(185, frameRect.size.height-35)];
	[bp9 lineToPoint:NSMakePoint(185, frameRect.size.height-55)];
	[bp9 lineToPoint:NSMakePoint(85, frameRect.size.height-55)];
	[bp9 closePath];
	[[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:alpha] set];
	[bp9 fill];
	
	NSBezierPath *bp10 = [[NSBezierPath alloc] init];
	[bp10 moveToPoint:NSMakePoint(86, frameRect.size.height-36)];
	[bp10 lineToPoint:NSMakePoint(186, frameRect.size.height-36)];
	[bp10 lineToPoint:NSMakePoint(186, frameRect.size.height-56)];
	[bp10 lineToPoint:NSMakePoint(86, frameRect.size.height-56)];
	[bp10 closePath];
	[[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:alpha] set];
	[bp10 fill];
	
	NSBezierPath *bp11 = [[NSBezierPath alloc] init];
	[bp11 moveToPoint:NSMakePoint(87, frameRect.size.height-37)];
	[bp11 lineToPoint:NSMakePoint(187, frameRect.size.height-37)];
	[bp11 lineToPoint:NSMakePoint(187, frameRect.size.height-57)];
	[bp11 lineToPoint:NSMakePoint(87, frameRect.size.height-57)];
	[bp11 closePath];
	[[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:alpha] set];
	[bp11 fill];
	
	NSBezierPath *bp12 = [[NSBezierPath alloc] init];
	[bp12 moveToPoint:NSMakePoint(107, frameRect.size.height-37)];
	[bp12 lineToPoint:NSMakePoint(207, frameRect.size.height-37)];
	[bp12 lineToPoint:NSMakePoint(107, frameRect.size.height-57)];
	[bp12 closePath];
	[[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:alpha] set];
	[bp12 fill];
	
	NSBezierPath *bp4 = [[NSBezierPath alloc] init];
	[bp4 moveToPoint:NSMakePoint(30, frameRect.size.height-5)];
	[bp4 lineToPoint:NSMakePoint(80, frameRect.size.height-30)];
	[bp4 moveToPoint:NSMakePoint(40, frameRect.size.height-5)];
	[bp4 lineToPoint:NSMakePoint(80, frameRect.size.height-30)];
	[bp4 moveToPoint:NSMakePoint(50, frameRect.size.height-5)];
	[bp4 lineToPoint:NSMakePoint(80, frameRect.size.height-30)];
	[bp4 moveToPoint:NSMakePoint(60, frameRect.size.height-5)];
	[bp4 lineToPoint:NSMakePoint(80, frameRect.size.height-30)];
	[[NSColor blackColor] set];
	[bp4 stroke];
	
	NSMutableAttributedString *s = [[NSMutableAttributedString alloc] initWithString:@"<0.19.0>"];
	[s addAttribute:NSFontAttributeName	
			  value:[NSFont userFontOfSize:14]
			  range:NSMakeRange(0,8)];
	[s addAttribute:NSForegroundColorAttributeName
			  value:[NSColor blackColor]
			  range:NSMakeRange(0,8)];
	NSRect text = NSMakeRect(100, frameRect.size.height-82, 70, 50);
	[s drawInRect:text];*/
	
}

- (BOOL) isFlipped
{
	return YES;
} 

-(void) viewDidEndLiveResize {
	[self setNeedsDisplay:YES];
}

- (void)test { // test resize
	NSSize framesize = NSMakeSize (3000.0, 3000.0);
	[self setFrameSize:framesize];
	[self setNeedsDisplay:YES];
}

@end
